﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SpaceFight
{
    abstract class BasicModel
    {
        public Model model;
        protected Matrix world = Matrix.Identity;

        public BasicModel(Model model)
        {
            this.model = model;
        }

        public virtual void Update()
        {
        }

        public virtual void Update(GameTime gametime)
        {
        }

        public void Draw(Camera camera)
        {
            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.Projection = camera.projection;
                    effect.View = camera.view;
                    //effect.World = GetWorld() * mesh.ParentBone.Transform;
                    effect.World = transforms[mesh.ParentBone.Index] * GetWorld();
                }
                mesh.Draw();
            }
        }



        public virtual Matrix GetWorld()
        {
            return world;
        }
    }
}
 